package com.hitown.controller.dxhd;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hitown.model.dxhd.DxhdRygkRysmz;
import com.hitown.service.dxhd.DxhdRygkRysmzService;
import com.hitown.util.Params;
import com.hitown.util.R;
import com.hitown.util.StringUtils;
import com.hitown.util.UUIDUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collection;
import java.util.Date;

/**
 * <p>
 * 人员管控-人员实名制动态信息 前端控制器
 * </p>
 *
 * @author menu
 * @since 2021-07-19
 */
@RestController
@RequestMapping("/dxhd-rygk-rysmz")
public class DxhdRygkRysmzController {

    @Autowired
    private DxhdRygkRysmzService dxhdRygkRysmzService;
    
    @ApiOperation(value = "分页查询")
    @RequestMapping("selectPage")
    public R selectPage(@ApiIgnore @RequestBody Params<DxhdRygkRysmz> params){
        Page<DxhdRygkRysmz> page = new Page<>(params.getCurrent(),params.getSize());
        QueryWrapper<DxhdRygkRysmz> wrapper =new QueryWrapper<>();
        wrapper.select("ID","GMSFHM","(select content from t_dictionary t where type='ZJDM' and id = CYZJDM) CYZJMC","CYZJDM","ZJHM","XM",
                "(select content from t_dictionary t where type='XB' and id = XBDM) XBMC","XBDM","(select content from t_dictionary t where type='GJ' and id = GJDM) GJMC","GJDM",
                "(select content from t_dictionary t where type='MZ' and id = MZDM) MZMC","MZDM","SBLX","SPSBBM","SBMC","JSFX","SBDZ","ZPSJ","TPURL","DQJD","DQWD","CJSJ","XXRKSJ",
                "CTU","CTM","UTU","UTM");
        //姓名
        if(!StringUtils.isEmpty(params.getEntity().getXm())){
            wrapper.like("XM", params.getEntity().getXm());
        }

        //公民身份号码
        if(!StringUtils.isEmpty(params.getEntity().getGmsfhm())) {
            wrapper.eq("GMSFHM",params.getEntity().getGmsfhm());

        }
        //性别代码
        if(!StringUtils.isEmpty(params.getEntity().getXbdm())) {
            wrapper.eq("XBDM",params.getEntity().getXbdm());

        }
        IPage<DxhdRygkRysmz> pageVo = dxhdRygkRysmzService.page(page,wrapper);
        return R.ok().put("data",pageVo);

    }


    @ApiOperation(value = "根据id查询记录")
    @RequestMapping("getById")
    public R getById(@RequestParam String Id){
        DxhdRygkRysmz result = dxhdRygkRysmzService.getById(Id);
        return R.ok().put("data",result);

    }

    @ApiOperation(value = "保存单条记录")
    @PostMapping("save")
    public R save(@RequestBody DxhdRygkRysmz entit){
        entit.setId(UUIDUtils.getUUID());
        Boolean result = dxhdRygkRysmzService.save(entit);
        return R.ok().put("data",result);
    }


    @ApiOperation(value = "批量保存")
    @RequestMapping("saveBatch")
    public R saveBatch(@RequestBody Collection<DxhdRygkRysmz> entityList){
        Boolean result = dxhdRygkRysmzService.saveBatch(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 选择修改")
    @RequestMapping("updateById")
    public R updateById(@RequestBody DxhdRygkRysmz entit){
        entit.setUtm(new Date());
//        Boolean result = dxhdRygkRysmzService.updateById(entit);
        return dxhdRygkRysmzService.updateDxhdRygkRysmz(entit);

    }


    @ApiOperation(value = "根据ID 批量更新")
    @RequestMapping("updateBatchById")
    public R updateBatchById(@RequestBody Collection<DxhdRygkRysmz> entityList){
        Boolean result = dxhdRygkRysmzService.updateBatchById(entityList);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "根据 ID 删除")
    @RequestMapping("removeById")
    public R removeById(@RequestParam String Id){
        Boolean result = dxhdRygkRysmzService.removeById(Id);
        return R.ok().put("data",result);

    }


    @ApiOperation(value = "删除（根据ID 批量删除）")
    @RequestMapping("removeByIds")
    public R removeByIds(@RequestBody Collection<String> Ids){
        Boolean result = dxhdRygkRysmzService.removeByIds(Ids);
        return R.ok().put("data",result);
    }
}

